package org.southyin.controller.cms_article;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.southyin.commons.CommonsPage;
import org.southyin.model.CmsArticle;
import org.southyin.service.CmsArticleService;
import org.southyin.service.impl.CmsArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/article/index")
public class CmsTagArticleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String listId = req.getParameter("listId");
        String pageSizeStr = req.getParameter("pageSize");
        String pageNumStr = req.getParameter("pageNum");
        int pageSize = -1;
        int pageNum = -1;
        listId = listId == null ? "1" : listId;
        pageSize = pageSizeStr == null ? 3 : Integer.valueOf(pageSizeStr);
        pageNum = pageNumStr == null ? 1 : Integer.valueOf(pageNumStr);
        CmsArticleService service = new CmsArticleServiceImpl();
        CommonsPage<CmsArticle> cmsArticleCommonsPage = service.listHotOrNewOrHotList(listId,pageNum,pageSize);
        resp.getWriter().println(new ObjectMapper().writeValueAsString(cmsArticleCommonsPage));
    }
}
